package com.woniuxy.yoga.progress.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import com.woniuxy.yoga.progress.dao.model.Moncard;
import com.woniuxy.yoga.progress.model.form.CreateMonCardForm;
import com.woniuxy.yoga.progress.model.param.CreateMonCardParam;
import com.woniuxy.yoga.progress.service.MoncardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 月卡流程表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/moncard")
@Api(tags = "月卡进度管理")
public class MoncardController {

    @Autowired
    private MoncardService moncardService;

    /**
     * 创建月卡进度表
     * @param form 创建月卡进度表参数
     * @return String
     */
    @PostMapping("/createMonCard")
    @ApiOperation("创建月卡进度表")
    @YogaLog("创建月卡进度表")
    public Result<?> createMonCard(@RequestBody @Valid CreateMonCardForm form) throws Exception {
        moncardService.createMonCard(BeanUtil.toBean(form, CreateMonCardParam.class));
        return Result.getResult().setMessage("创建月卡进度表成功");
    }

    /**
     * 查询未完成月卡进度
     * @param userId userid
     * @return Moncard
     */
    @GetMapping("/getUnfinishMon/{userId}")
    @ApiOperation("查询未完成月卡")
    @YogaLog("查询未完成月卡")
    public Result<List<Moncard>> getUnfinishMon(@PathVariable("userId") @Valid @NotNull Integer userId){
        List<Moncard> moncards = moncardService.getUnfinishMon(userId);
        return Result.getListResult(Moncard.class).setData(moncards).setMessage("查询成功");
    }

}

